package com.example.demo.error;

import com.example.demo.error.Unify.UnifyResponse;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;




@ControllerAdvice
@ResponseBody
//@EnableWebMvc 这个是用不到了



//用于配置异常的类
public class GlobalExceptionAdvice {

    @ExceptionHandler(Exception.class)

    public UnifyResponse handleException(HttpServletRequest req , Exception e){
        System.out.println("hello error?");
        UnifyResponse message =new UnifyResponse(19991,"服务器异常","GET") ;
        return message ;
    }

    @ExceptionHandler(value =  HttpException.class)
    public UnifyResponse handleHttpException(HttpServletRequest req , Exception e){

        System.out.println("hello httperror?");
        UnifyResponse message =new UnifyResponse(1999651,"服务器异常","GET") ;
        return message ;
    }
}
